//
//  ReturnViewController.m
//  BasketballClub
//
//  Created by 孙鸿吉 on 16/1/18.
//  Copyright © 2016年 孙鸿吉. All rights reserved.
//

#import "ReturnViewController.h"
#import "ReturnView.h"
#import <AVOSCloud.h>
@interface ReturnViewController ()
@property (nonatomic,strong)ReturnView *returnView;
@end

@implementation ReturnViewController
- (void)loadView
{
    self.returnView = [[ReturnView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.view = self.returnView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.returnView.backgroundColor = ColorHex(0x0d1c38);
    //返回按钮
    [self.returnView.cancleButton addTarget:self action:@selector(returnBeforeAction) forControlEvents:UIControlEventTouchUpInside];
    //发送按钮
    [self.returnView.sendButton addTarget:self action:@selector(sendButtonAction) forControlEvents:UIControlEventTouchUpInside];
    //添加手势
    UIScreenEdgePanGestureRecognizer *edgeGR = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(edgeGR)];
    [self.returnView addGestureRecognizer:edgeGR];
    self.returnView.userInteractionEnabled = YES;
    edgeGR.edges = UIRectEdgeLeft;
}
#pragma mark - 取消按钮方法
- (void)returnBeforeAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 发送按钮方法
- (void)sendButtonAction
{
    AVObject *ob = [AVObject objectWithClassName:@"returnSuggestion"];
    [ob setObject:self.returnView.returnTextView.text forKey:@"suggestion"];
    [ob saveInBackground];
    [self logoutSuccess];
    
}

#pragma mark - 提示框(发送成功)
- (void)logoutSuccess
{
    CGFloat verison = [[[UIDevice currentDevice]systemVersion]floatValue];
    if (verison >= 8.0) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"发送成功" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:nil];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self dismissViewControllerAnimated:YES completion:nil];
        });
        
    }else{
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"发送成功" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
        [alertView show];
        
        [self performSelector:@selector(aftertimeAction:) withObject:alertView afterDelay:2.0];
    }
    
}
#pragma mark - 延迟2秒方法
- (void)aftertimeAction:(UIAlertView *)sender
{
    [sender dismissWithClickedButtonIndex:0 animated:YES];
    
}
#pragma mark - 手势方法实现
- (void)edgeGR
{
    [self dismissViewControllerAnimated:YES completion:nil];
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
